package com.whu.gc.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.whu.gc.service.InsertResponseService;
import com.whu.gc.service.ShowResponseService;
import com.whu.pojo.Car;
import com.whu.pojo.Response;

@Controller
@RequestMapping("forum")
public class ForumController {
	
	@Autowired
	ShowResponseService showResponseService;

	
	@RequestMapping("/showResponse")
	public ModelAndView showResponse() throws Exception{
		//调用service查找 数据库，查询商品列表
		
		List<Response> responseList = new ArrayList<Response>();
		responseList = showResponseService.showResponse(1);
//
//		//返回ModelAndView
		ModelAndView modelAndView =  new ModelAndView();
//		//相当 于request的setAttribut，在jsp页面中通过itemsList取数据
		modelAndView.addObject("responseList", responseList);
		System.out.println(responseList);
		modelAndView.setViewName("forum");
		
		return modelAndView;
	}
	
	@Autowired
	InsertResponseService insertResponseService;
	
	@RequestMapping("/insertResponse")
	public ModelAndView insertResponse(Response response)throws Exception{
		
		System.out.println(insertResponseService.selectltpl08(response));
		response.setLtpl08(insertResponseService.selectltpl08(response));
		int i=insertResponseService.insertResponse(response);
		System.out.println(response);
		ModelAndView modelAndView =  new ModelAndView();
		if(i==1) {
		modelAndView.addObject("result","发表成功" );
		}
		
		List<Response> responseList = new ArrayList<Response>();
		responseList = showResponseService.showResponse(1);
		modelAndView.addObject("responseList", responseList);
		modelAndView.setViewName("forum");
		return modelAndView;
	}
}
